import axios from '@/utils/request'
/**
 *用户登录
 * @param {*} mobile 手机号
 * @param {*} code 密码
 * @returns
 */
export function userReg(mobile, password) {
  return axios({
    method: 'post',
    url: '/index/reg',
    data: {
      mobile: mobile,
      password: password
    }
  })
}
export function userLogin(mobile, password) {
  return axios({
    method: 'post',
    url: '/index/login',
    data: {
      mobile: mobile,
      password: password
    }
  })
}

export function userInfo() {
  return axios({
    method: 'GET',
    url: '/user/getUserInfo'
  })
}
// 首页热门推荐
export function homeHot() {
  return axios({
    method: 'GET',
    url: '/index/hot'
  })
}

// 首页信息
export function homeIndex() {
  return axios({
    method: 'GET',
    url: '/index/index'
  })
}
// 首页最近更新列表
export function homenNew(page) {
  return axios({
    method: 'GET',
    url: '/index/new',
    params: {
      page: page,
      limit: 10
    }
  })
}
// 修改个人信息
export function uodateUser(type) {
  return axios({
    method: 'POST',
    url: '/user/update',
    data: type
  })
}

// 文章信息
export function acticleID(ids) {
  return axios({
    method: 'GET',
    url: '/index/show',
    params: { id: ids }
  })
}

/**
 * 点赞，收藏文章
 *
 * @num 1是收藏 ，2 是点赞
 * @ids 文章id
 * @actions add 点赞，del 取消
 */
export function addCollect(num, ids, actions) {
  return axios({
    method: 'GET',
    url: '/user/userDataHandle',
    params: { type: num, article_id: ids, action: actions }
  })
}

/**
 * 分类列表
 *
 * @page
 * @limit
 * @cateid 分类id
 */
export function sortList(page, cateid) {
  return axios({
    method: 'GET',
    url: '/index/list',
    params: { page, limit: 20, cateid }
  })
}

/**
 * 分类列表
 *
 * @
 * @ cateid 分类id
 * @status 文章状态，1草稿，2发布
 */
export function addArticle(author, cateid, content, pic, status, tags, title) {
  return axios({
    method: 'POST',
    url: '/user/addArticle',
    data: { author, cateid, content, pic, status, tags, title }
  })
}

export function Myarticle(page) {
  return axios({
    method: 'GET',
    url: '/user/myArticle',
    params: { page, limit: 10 }
  })
}

export function delArticle(id) {
  return axios({
    method: 'GET',
    url: 'user/delArticle',
    params: { id }
  })
}

export function upload(file) {
  return axios({
    method: 'POST',
    url: '/common/upload?type=images',
    data: file
  })
}

/**
 * 分类列表
 *
 * @
 * @ cateid 分类id
 * @status 文章状态，1草稿，2发布
 */
export function editArticle(
  author,
  cateid,
  content,
  pic,
  status,
  tags,
  title,
  id
) {
  return axios({
    method: 'POST',
    url: '/user/editArticle',
    data: { author, cateid, content, pic, status, tags, title, id }
  })
}

export function userDataList(type, page) {
  return axios({
    method: 'GET',
    url: '/user/userDataList',
    params: { type, page, limit: 10 }
  })
}
